<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>AMD</title>
    <script src="./require.js"></script>
  </head>
  <body>
    <script>
      // 配置RequireJS
      require.config({
        baseUrl: "./",
        paths: {
          // 这里可以定义模块的路径别名
        },
      });
      define("a", function () {
        return {
          add: function (a, b) {
            return a + b;
          },
        };
      });

      define("b", ["a"], function (a) {
        return {
          calculate: function () {
            return a.add(1, 2);
          },
        };
      });

      require(["b"], function (b) {
        console.log(b.calculate());
      });
    </script>
  </body>
</html>
